<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>企业主页</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/homePage.css" />
		<link rel="stylesheet" href="../css/style.css" /> 
		<style>
		body{font-size:15px}
		/*九宫格修改*/
		.mui-grid-view.mui-grid-9 .mui-table-view-cell{border:none;padding:0 5px}
		.mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-body{margin-top:0}
		/*大图新闻*/
		.zone>a{color:#333}
		.zone>a>div{margin-bottom:10px}
		.render-title{font-weight: 700;color:#000}
		.render-time{float: right}
		</style>
		
	</head>
	<body> 
		
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/delayimg.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			
			//mui初始化
			mui.init();		  
			  	
		</script>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">  		
			<div class="mui-scroll">
				<div id="slider" class="mui-slider  ">
					<div class="mui-slider-group mui-slider-loop" id="sliderImg">
					</div>
					<div class="mui-slider-indicator">
					</div>
					<div class="mui-pull-loading mui-spinner custom-loading"></div>
				</div>
				
				
		        <ul class="mui-table-view mui-grid-view mui-grid-9">
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/js.png" class="mui-grid-img">
		                    <div class="mui-media-body">健身</div></a></li>
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/zlyi.png" class="mui-grid-img">
		                    <div class="mui-media-body">社保咨询</div></a></li>
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/zz.png" class="mui-grid-img">
		                    <div class="mui-media-body">玩游戏</div></a></li>
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/yx.png" class="mui-grid-img">
		                    <div class="mui-media-body">短租房</div></a></li>
		           	<li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/js.png" class="mui-grid-img">
		                    <div class="mui-media-body">健身</div></a></li>
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/zlyi.png" class="mui-grid-img">
		                    <div class="mui-media-body">社保咨询</div></a></li>
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/zz.png" class="mui-grid-img">
		                    <div class="mui-media-body">玩游戏</div></a></li>
		            <li class="mui-table-view-cell mui-media  mui-col-xs-3"><a href="#">
		                    <img src="../images/yx.png" class="mui-grid-img">
		                    <div class="mui-media-body">短租房</div></a></li>
	               
		            
		        </ul> 
		        <!--招标列表-->
		        <h3 class="custom-title">最新招标</h3>
				<ul class="mui-table-view" id="renderList"> 
				    <li class="mui-table-view-cell mui-media">
				        <a href="javascript:;" class="c-href" data-href="./tender.html#">
				            <img class="mui-media-object mui-pull-left" src="../images/h07.png">
				            <div class="mui-media-body">
				
				                <p class="mui-ellipsis render-title">工作服(国电龙源江永风力发电有限公司)询价采购</p>
				                <span class="mui-badge render-time">2017/02/03</span>
				            </div>
				        </a>
				    </li>
				    <li class="mui-table-view-cell mui-media">
				        <a href="javascript:;" class="c-href" data-href="./tender.html#">
				            <img class="mui-media-object mui-pull-left" src="../images/h08.png">
				            <div class="mui-media-body"> 
				                 <p class="mui-ellipsis render-title">广播系统购置招标公告[长沙王府井]</p>
				                <span class="mui-badge render-time">2017/02/03</span>
				            </div>
				        </a>
				    </li>
				   
				</ul>
		        <h3 class="custom-title">热销商品</h3> 
				<ul style="margin-bottom: 0px;padding-bottom: 0px"class="mui-table-view mui-grid-view mui-clearfix vshop-product" id="productsList">
				</ul>
				<h3 style="margin-top: 0px;padding-top: 0px"class="custom-title" >热门企业</h3>  
				<ul class="mui-table-view mui-grid-view mui-clearfix vshop-product" id="companys">
				</ul>
				<div style="padding:0 5px;background:#fff"> 
					<!--推荐新闻-->
					<ul class="mui-table-view news-ul" id="newsList">
					    <li class="mui-table-view-cell mui-media">
					        <a href="javascript:;">
					            <img class="mui-media-object mui-pull-right" src="../images/h07.png">
					            <div class="mui-media-body">
					                <strong>幸福啊</strong>
					                <p class="mui-ellipsis">能和心爱的人一起睡觉，是件幸福的事情；可是，打呼噜怎么办？</p>
					            </div>
					        </a>
					    </li>
					    <li class="mui-table-view-cell mui-media">
					        <a href="javascript:;">
					            <img class="mui-media-object mui-pull-right" src="../images/h08.png">
					            <div class="mui-media-body">
					                <strong>幸福</strong>
					                <p class="mui-ellipsis">想要这样一间小木屋，夏天挫冰吃瓜，冬天围炉取暖.</p>
					            </div>
					        </a>
					    </li> 
					    <li class="mui-table-view-cell mui-media">
					        <a href="javascript:;">
					            <img class="mui-media-object mui-pull-right" src="../images/h09.png">
					            <div class="mui-media-body">
					                <strong>幸福</strong>
					                <p class="mui-ellipsis">烤炉模式的城，到黄昏，如同打翻的调色盘一般.</p>
					            </div>
					        </a>
					    </li>
					    <li class="mui-table-view-cell">
					    	<div class="zone" id="zoneImg">					
								<a>
									<div>
										<strong>一小时换衣服数十套,他们站出千万级生意</strong>
									</div>					
									<img src="../images/e02.png"/>   							
								</a>
								
							</div>
					    </li>
					    <li class="mui-table-view-cell mui-media">
						        <a class="c-href" href="javascript:;">
						            <img class="mui-media-object mui-pull-right" src="../images/h07.png">
						            <div class="mui-media-body">
						                <strong>幸福</strong>
						                <p class="mui-ellipsis">能和心爱的人一起睡觉，是件幸福的事情；可是，打呼噜怎么办？</p>
						            </div>
						        </a>
						    </li>
						    <li class="mui-table-view-cell mui-media">
						        <a href="javascript:;">
						            <img class="mui-media-object mui-pull-right" src="../images/h08.png">
						            <div class="mui-media-body"> 
						                <strong>幸福</strong>
						                <p class="mui-ellipsis">想要这样一间小木屋，夏天挫冰吃瓜，冬天围炉取暖.</p>
						            </div>
						        </a>
						    </li>
						    <li class="mui-table-view-cell mui-media">
						        <a href="javascript:;">
						            <img class="mui-media-object mui-pull-right" src="../images/h09.png">
						            <div class="mui-media-body">
						                <strong>幸福</strong>
						                <p class="mui-ellipsis">烤炉模式的城，到黄昏，如同打翻的调色盘一般.</p>
						            </div>
						        </a>
						    </li>
					</ul>
					<!--圈子-->
					
					
					
				</div>
			</div>
		</div>
	<script type="text/javascript">
		var slider = document.getElementById('sliderImg');
		var slider2 = document.getElementById('sliderImg2');
		var newsHot = document.getElementById('newsHot');
		var companys = document.getElementById('companys');
		var newsList = document.getElementById('newsList');
		var loadArr =document.getElementsByClassName('custom-loading');
		var page = 1,
			isnodata = false;
		mui.init({
				swipeBack: false,
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						contentdown : "下拉可以刷新",
						contentover : "释放立即刷新",
						contentrefresh : "正在刷新...",
						callback :function(){
							setTimeout(function(){
								page = 1;
								isnodata = false;
								loadPage();
								mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
								mui('#pullrefresh').pullRefresh().refresh(true);
							},300)
						}
					},
					up: {
						contentrefresh: '正在刷新...',
						callback: pullupRefresh,
						height:200,
					}
				}
			});
		
		/**
		 * 上拉加载具体业务实现 
		 */
		function pullupRefresh() {			
			var self=this;
	      	setTimeout(function() {
	      		console.log('aaa'+isnodata);
		      	if (!isnodata) {
		      		console.log('aaa2'+isnodata);
		      		page++;
			        mui.ajax(url+'/homePage/GetIndex?webToken=rqlh&currentPage='+page+'&pageSize=5',{
						dataType:'json',
						type:'get',
						timeout:10000,
						success:function(data){
							if(data.Code=='000'){
			                    var html = '';				                   
			                    delayimg.render();
			                    if (data.NewsList.length<5) {isnodata = true;}
								self.endPullupToRefresh(isnodata);
								console.log('aaa200'+isnodata);
								//新闻列表
								var news="";
								var newsLen=data.NewsList.length;
								for (var i = 0; i < newsLen; i++) {					            	
					            	news+='<li class="mui-table-view-cell mui-media"><a class="c-href" data-href="./news.html#'+data.NewsList[i].id+'"><img src="'+data.NewsList[i].src+'" class="mui-media-object mui-pull-right"><div class="mui-media-body"><strong>'+data.NewsList[i].name+'</strong><p class="mui-ellipsis">'+data.NewsList[i].msg+'</p></div></a></li>';						                
								}		
								console.log(news)
								newsList.insertAdjacentHTML("beforeend",news); 
							}
						},
						error:function(xhr,type,errorThrown){
							plus.nativeUI.toast('请求失败，请检查网络')
						}
					});
			    }else{
			    	console.log('aaa3');
			    	self.endPullupToRefresh(isnodata);
			    }
		    },1500);
//				mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
//				var table = document.body.querySelector('.news-ul');
//				var cells = document.body.querySelectorAll('.mui-media');
//				
//				for (var i = cells.length, len = i + 3; i < len; i++) {
//					var li = document.createElement('li');
//					li.className = 'mui-table-view-cell mui-media';
//					var html = '<a href="javascript:;">'
//					            +'<img class="mui-media-object mui-pull-right" src="../images/h09.png">'
//					            +'<div class="mui-media-body">'
//					            +'<strong>刷新成功'+i+'</strong>'
//					            +'<p class="mui-ellipsis">烤炉模式的城，到黄昏，如同打翻的调色盘一般.</p>'
//					            +'</div></a>'
//					            
//					li.innerHTML = html	        
//					table.appendChild(li);
//				}
//			}, 1000);
		}
		//添加首页热销商品
		function initData(html,data){
				for (var i = 0; i < 3; i++) {
                    html += '<li class="mui-table-view-cell mui-media mui-col-xs-4">'+
            			'<div class="index-product-box">';
    				 
					html +='<a data-id="'+data.Product[i].Id+'">'+
					'<div class="p-img"><b data-delay-background="'+data.Product[i].ImageUrl+'"></b></div>'+
					'<div class="mui-media-body">'+data.Product[i].Name+'</div>'+
					'<p class="index-product-price"><span>¥ '+data.Product[i].SalePrice+'</span> </p>'+
					'</a>'+ 
					'</div>'+
            		'</li>';
                }
				return html;  
		}
		mui.plusReady(function() {
			mui.ajax(URL+'api/home/Get?pageNo=1&pageSize=4',{
						dataType:'json',
						type:'get',
						success:function(data){
							if(data.Success=='true'){
								
								//第一页商品
//								if (data.TotalProduct<=10) {isnodata = true;}
								if (data.Product.length > 0) {
				                    var html = '';
				                    document.getElementById('productsList').innerHTML=initData(html,data);
				                    //图片延迟加载初始化
				                    delayimg.init();
				                }
								window.scrollTo(0,0)
								plus.navigator.closeSplashscreen();
								document.getElementById('pullrefresh').className='mui-content mui-scroll-wrapper';
							}
						}, 
						error:function(xhr,type,errorThrown){
							plus.navigator.closeSplashscreen();
							var errorText='<div class="empty-show"><h4>网络不给力，请检查网络！</h4><button id="reloadWv" class="mui-btn mui-btn-negative">重新加载</button></div>'
							document.getElementById('pullrefresh').innerHTML=errorText;
							document.getElementById('pullrefresh').className='mui-content mui-scroll-wrapper';
						}
				});
			//添加列表项的点击事件
			mui('#productsList').on('tap', 'a', function(e) {
				var id = this.getAttribute('data-id');
				showProduct(id,'/');
				console.log('aaaa');
			}); 
			setTimeout(function(){
				for(var i=loadArr.length-1; i>=0; i--){
					loadArr[i].parentNode.removeChild(loadArr[i]);
				}
			},5000);
			loadPage=function(){	 
					mui.ajax(url+'/homePage/GetIndex?currentPage=1&pageSize=5',{
								dataType:'json',
								data:{
									webToken:'rqlh' 
								},
								type:'get',
								timeout:10000,
								success:function(data){									
									//轮播图
									var imgLen=data.Carousel1.length;
									if(imgLen>1){
										
										var outputimg =""; 
							            var outputright = "";   
				 			            
							            outputimg+='<div class="mui-slider-item mui-slider-item-duplicate"><a class="c-href" data-href="'+data.Carousel1[imgLen-1].url+'"><img src="'+data.Carousel1[imgLen-1].src+'" /></a></div>';
							            for (var i = 0; i < imgLen; i++) {
							            	
							            	outputimg+='<div class="mui-slider-item"><a class="c-href" data-href="'+data.Carousel1[i].url+'"><img src="'+data.Carousel1[i].src+'" /></a></div>';
							                outputright += '<div class="mui-indicator'+(i == 0?' mui-active':'')+'"></div>';
							            }
							            
							            outputimg+='<div class="mui-slider-item mui-slider-item-duplicate"><a class="c-href" data-href="'+data.Carousel1[0].url+'"><img src="'+data.Carousel1[0].src+'"  /></a></div>';
							          	
							            slider.innerHTML=outputimg; 
							            console.log(outputright);
							            document.getElementsByClassName('mui-slider-indicator').innerHTML=outputright;
							              console.log(outputimg);
										mui('#slider').slider({interval:5000});    
										
									}else if(imgLen==1){ 
										slider.innerHTML='<div class="mui-slider-item"><a class="c-href" data-href="'+data.Carousel1[0].url+'"><img src="'+data.Carousel1[0].src+'" style="width:100%" /></a></div>';
										mui('#slider').slider();
										 
									}else{
										document.getElementById('slider').style.display='none';
									}
									//热点新闻  
									var hotnews=""; 
									var hotLen=data.HotNews.length;
									for (var i = 0; i < hotLen; i++) {
						            	
						            	hotnews+='<li  class="mui-table-view-cell mui-media "><a class="c-href" data-href="./news.html#'+data.HotNews[i].id+'"><img src="'+data.HotNews[i].src+'" class="mui-media-object mui-pull-right"><div class="mui-media-body"><strong>'+'新闻名字'+'</strong><p class="mui-ellipsis">'+data.HotNews[i].msg+'</p></div></a></li>';
						                 
									}
									newsList.innerHTML= hotnews ;
//									companys.insertAdjacentHTML("beforeend",hotnews);
									
									
									
									//新闻列表
									var news="";
									var newsLen=data.NewsList.length;
									for (var i = 0; i < newsLen; i++) {
						            	
						            	news+='<li class="mui-table-view-cell mui-media"><a class="c-href" data-href="./news.html#'+data.NewsList[i].id+'"><img src="'+data.NewsList[i].src+'" class="mui-media-object mui-pull-right"><div class="mui-media-body"><strong>'+data.NewsList[i].name+'</strong><p class="mui-ellipsis">'+data.NewsList[i].msg+'</p></div></a></li>';
						                
									}
//									companys.innerHTML= news ;  
									newsList.insertAdjacentHTML("beforeend",news); 
									//推荐公司		 
									var company="";
									
									var comLen=data.Company.length;
									for (var i = 0; i < comLen; i++) {
					                    company += '<li class="mui-table-view-cell mui-media mui-col-xs-6">'+
					            			'<div class="index-product-box">';
					            				 
													company +='<a class="c-href" data-href="./company.html#'+data.Company[i].id+'">'+
													'<div class="p-img"><b data-delay-background="'+data.Company[i].src+'"></b></div>'+
													'<div class="mui-media-body">'+data.Company[i].name+'</div>'+
												'</a>'+ 
											'</div>'+
					            		'</li>';
					                }
									
									console.log(company);     
									console.log("haha");
//									companys.innerHTML= company ;  
									companys.innerHTML=company;
									delayimg.init();
									
								},
								error:function(xhr,type,errorThrown){
									console.log("error");
									   
								}
								   
									  
					}); 
				}
				loadPage()
				/*页面跳转*/
				mui('.mui-content').on('tap', '.c-href', function() {
						console.log("aaaaaaa");
						console.log("tap");
						var href=this.getAttribute('data-href').toLowerCase(),
							id;
						if(href.indexOf('product/detail/')>=0){
							id=href.split('product/detail/')[1];
							showProduct(id);
						 	
						}else if(href.indexOf('topic/detail/')>=0){
							id=href.split('topic/detail/')[1];
							himall.openVW('topic-detail.html','',{topicId:id});
							
						}else if(href.indexOf('./company')>=0){
							console.log(href);  
							id=href.split('./company.html#')[1];
							console.log(id);
							himall.openVW('./company.html','./company.html',{companyId:id});
							
						}else if(href.indexOf('./news')>=0){
							console.log(href);
							id=href.split('./news.html#')[1];
							console.log(id);
							himall.openVW('./news.html','./news.html',{newsId:id}); 
							
						} else if(href.indexOf('./tender')>=0){
							console.log(href);
							himall.openVW('./tender.html','./tender.html'); 
						}
							
						else{
							plus.runtime.openURL(href);
							console.log('aaa');  
						}
				});
		})
	</script>
	</body>
	
</html>